//
//  TFGiftExchangeCashVC.m
//  project
//
//  Created by yefei on 2019/4/15.
//  Copyright © 2019 健健. All rights reserved.
//

#import "YFGiftExchangeCashVC.h"
#import "YFCashView.h"

@interface YFGiftExchangeCashVC ()

@property (nonatomic,strong) YFCashView *cashView;

@property (weak, nonatomic) IBOutlet UITableView *tableView;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *tableViewConstraintTop;


@end

@implementation YFGiftExchangeCashVC

- (void)viewDidLoad {
    [super viewDidLoad];
    self.navTitle = @"兑换现金";
    [self setupView];
}

- (void)setupView {
    [self setupTableView];
    [self setupCashView];
}

- (void)setupTableView {
    
    self.tableView.tableHeaderView = self.cashView;
    self.tableView.tableFooterView = [UIView new];
    self.tableView.contentInset = UIEdgeInsetsMake(0, 0, SAFE_AREA_HEIGHT, 0);
}

- (void)setupCashView {
    
    self.cashView.price = self.price;
    self.cashView.totalAmount = self.totalAmount;
    self.cashView.totalPrice = self.totalPrice;
    self.cashView.serviceCharge = self.serviceCharge;
}

#pragma mark - Lazy Load

- (YFCashView *)cashView {
    if (!_cashView) {
        _cashView = [YFCashView loadFromXib:[YFCashView class]];
        CGFloat height = 400;
        
        CGFloat contentHeight = SCREEN_HEIGTH - NAVIGATION_BAR_HEIGHT - SAFE_AREA_HEIGHT;
        
        if (height < contentHeight) {
            height = contentHeight;
        }
        
        _cashView.frame = CGRectMake(0, 0, SCREEN_WIDTH, height);
    }
    return _cashView;
}

#pragma mark - 更新约束
- (void)updateViewConstraints {
    [super updateViewConstraints];
    self.tableViewConstraintTop.constant = NAVIGATION_BAR_HEIGHT;
}

@end


